<?php
/**
 * Class for CMSDocument
 *
 * @author Marcel Linnenfelser
 * @package
 * @since 13.11.2009
 * @license XICS License
 */
class base_templateEngine_CMSDocument implements ArrayAccess {

    private $doc = array();

    public function __construct ($doc) {
        $this->doc = $doc;
        phpinchains_ApplicationContext::getInstance()->debug('Method CMSDocument::__construct Id: '.$this->doc['id'].' Site Id: '.$this->doc['site-id']);
    }

    /**
     * Site ID
     * @return int
     */
    public function getSiteId () {
        return (int) $this->doc['site_id'];
    }

    /**
     * Site ID
     * FIXME: work with some kind of site object
     * @return array
     */
    public function getSite () {
        return base_ApplicationContext::getInstance()->getAccessFactory()->getInstanceOf(base_AccessFactory::$Sites)->get($this->getSiteId());
    }

    /**
     * Document ID
     * @return int
     */
    public function getId () {
        return (int) $this->doc['id'];
    }

    /**
     * Filename
     * @return string
     */
    public function getName () {
        return $this->doc['name'];
    }

    /**
     * ID of the parent document
     * @return int
     */
    public function getParentId () {
        return (int) $this->doc['parent_id'];
    }

    /**
     * Type of the document
     *
     * enum('index', 'folder', 'doc', 'inc', 'frame')
     *
     * @return string
     */
    public function getType () {
        return (int) $this->doc['type'];
    }

    /**
     * Page visible in navigation
     *
     * @return bool
     */
    public function isNavVisible () {
        return $this->doc['nav_visible'] == 'Y';
    }

    /**
     * Page visible in sitemap
     *
     * @return bool
     */
    public function isSitemapVisible () {
        return $this->doc['sitemap_visible'] == 'Y';
    }

    /**
     * Get header template
     *
     * @return string
     */
    public function getHeaderTemplate () {
        return $this->doc['headertpl'];
    }

    /**
     * Get content template
     *
     * @return string
     */
    public function getContentTemplate () {
        return $this->doc['contenttpl'];
    }

    /**
     * Get footer template
     *
     * @return string
     */
    public function getFooterTemplate () {
        return $this->doc['footertpl'];
    }

    /**
     * Get publish type
     *
     * enum('dynamic', 'static')
     *
     * @return string
     */
    public function getPublishType () {
        return $this->doc['publishtype'];
    }

    /**
     * Get built
     *
     * @return string
     */
    public function getBuilt () {
        return $this->doc['built'];
    }

    /**
     * Get modified
     *
     * @return string
     */
    public function getModified () {
        return $this->doc['modified'];
    }

    /**
     * Get published
     *
     * @return string
     */
    public function getPublished () {
        return $this->doc['published'];
    }

    /**
     * ID of the owner
     * @return int
     */
    public function getOwnerId () {
        return (int) $this->doc['owner'];
    }

    /**
     * FIXME: work with some kind of user object
     * @return array
     */
    public function getOwner () {
        $userdba = base_ApplicationContext::getInstance()->getAccessFactory()->getInstanceOf(base_AccessFactory::$User);
        return $userdba->get($this->getOwnerId());
    }


    // *** ArrayAccess methods

    /**
     *
     * @param string $offset
     */
    public function offsetExists ($offset) {
        return array_key_exists($offset, $this->doc);
    }

    /**
     *
     * @param string $offset
     * @return mixed
     */
    public function offsetGet ($offset) {
        return $this->doc[$offset];
    }

    /**
     * @param string $offset
     * @param mixed $value
     */
    public function offsetSet ($offset, $value) {
        $this->doc[$offset] = $value;
    }

    /**
     * @param string $offset
     */
    public function offsetUnset ($offset) {
        unset($this->doc[$offset]);
    }


    
    /**
     *
     * @return elements Elements object
     */
    public function getElements () {
        return $this->doc['elements'];
    }
}
